package com.huawei.appmarket.service.permissions;

import android.annotation.TargetApi;
import android.app.ActionBar;
import android.os.Bundle;
import com.huawei.appmarket.framework.activity.SecureActivity;
import com.huawei.appmarket.service.permissions.PermissionsProtocol.Request;
import o.cks;
import o.Logger;
import o.ContentManager;
import o.edc;
import o.edd;
import o.epz;
import o.ety;
import o.NetWorkUtil;

public final class PermissionsActivity extends SecureActivity<PermissionsProtocol> {
    private boolean ˊॱ = true;
    private int ˋॱ = -1;
    private int ͺ = 0;

    class e implements cks {
        private boolean ˊ;
        final /* synthetic */ PermissionsActivity ˎ;
        private String[] ॱ;

        public e(PermissionsActivity permissionsActivity, boolean z, String[] strArr) {
            this.ˎ = permissionsActivity;
            this.ˊ = z;
            this.ॱ = strArr;
        }

        public void enableNetworking() {
            if (this.ˊ) {
                this.ˎ.requestPermissions(this.ॱ, this.ˎ.ˋॱ);
                return;
            }
            try {
                NetWorkUtil.setWIfi(this.ˎ.getApplicationContext(), ContentManager.getInstant().getContext().getPackageName());
            } catch (Exception e) {
                Logger.ˎ("PermissionsActivity", "startActivity MANAGE_APP_PERMISSIONS failed! e = " + e.getMessage());
            }
            edc.ˋ().ॱ(this.ˎ.ˋॱ, new int[]{-1});
            this.ˎ.finish();
        }

        public void upgrade() {
            edc.ˋ().ॱ(this.ˎ.ˋॱ, new int[]{-1});
            this.ˎ.finish();
        }

        public void ˋ() {
        }
    }

    public void onCreate(Bundle bundle) {
        int i;
        super.onCreate(bundle);
        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }
        this.ˋॱ = bundle != null ? bundle.getInt("request_code", -1) : -1;
        if (bundle != null) {
            i = bundle.getInt("tips_res_id", 0);
        } else {
            i = 0;
        }
        this.ͺ = i;
        if (this.ˋॱ == -1) {
            PermissionsProtocol permissionsProtocol = (PermissionsProtocol) ʾ();
            if (permissionsProtocol != null) {
                Request ˊ = permissionsProtocol.ˊ();
                if (ˊ != null) {
                    String[] ॱ = ˊ.ॱ();
                    this.ˋॱ = ˊ.ˎ();
                    this.ͺ = ˊ.ˏ();
                    this.ˊॱ = ˊ(ॱ);
                    Logger.ˏ("PermissionsActivity", "onCreate() isShow : " + this.ˊॱ);
                    edd.ˏ(this, this.ˋॱ, ॱ);
                }
            }
        }
    }

    public void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        bundle.putInt("request_code", this.ˋॱ);
        if (this.ͺ > 0) {
            bundle.putInt("tips_res_id", this.ͺ);
        }
    }

    public void onResume() {
        super.onResume();
    }

    @TargetApi(21)
    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        this.ˋॱ = i;
        if (edd.ˊ(iArr)) {
            edc.ˋ().ॱ(i, iArr);
            finish();
        } else if (this.ͺ > 0) {
            boolean ˊ = ˊ(strArr);
            Logger.ˏ("PermissionsActivity", "onRequestPermissionsResult() isCanShowPermission : " + ˊ + " showTipsDialog : " + ॱॱ());
            if (ˊ || ॱॱ()) {
                ˎ(ˊ, strArr, this.ͺ);
                return;
            }
            edc.ˋ().ॱ(this.ˋॱ, new int[]{-1});
            finish();
        } else {
            edc.ˋ().ॱ(this.ˋॱ, iArr);
            finish();
        }
    }

    public boolean ॱॱ() {
        PermissionsProtocol permissionsProtocol = (PermissionsProtocol) ʾ();
        if (permissionsProtocol == null) {
            return false;
        }
        Request ˊ = permissionsProtocol.ˊ();
        if (ˊ == null) {
            return false;
        }
        boolean z = this.ˊॱ || !ˊ.ˊ();
        return z;
    }

    @TargetApi(23)
    public boolean ˊ(String[] strArr) {
        if (epz.ॱ(strArr)) {
            return false;
        }
        for (String shouldShowRequestPermissionRationale : strArr) {
            if (shouldShowRequestPermissionRationale(shouldShowRequestPermissionRationale)) {
                return true;
            }
        }
        return false;
    }

    @TargetApi(24)
    private void ˎ(boolean z, String[] strArr, int i) {
        ety.ॱ().ˏ(this, new e(this, z, strArr), i);
    }
}
